#ifndef KUN_RANDER_PIPELINE_TOON_OUTLINE_PASS_INCLUDED
#define KUN_RANDER_PIPELINE_TOON_OUTLINE_PASS_INCLUDED

#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"

struct Attributes
{
    float4 positionOS       : POSITION;
    float3 normalOS          : NORMAL;
    UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct Varyings
{
    float4 positionCS       : SV_POSITION;
    UNITY_VERTEX_INPUT_INSTANCE_ID
    UNITY_VERTEX_OUTPUT_STEREO
};



CBUFFER_START(UnityPerMaterial)
    // outline
    float3 _OutlineColor;
    float _OutlineWidth;

CBUFFER_END


Varyings ToonOutlinePassVertex(Attributes input)
{
    #ifndef _OUTLINE_ENABLE_ON
        return(Varyings)0;
    #endif

    Varyings output = (Varyings)0;

    UNITY_SETUP_INSTANCE_ID(input);
    UNITY_TRANSFER_INSTANCE_ID(input, output);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

    float4 positionCS = mul(UNITY_MATRIX_MVP, input.positionOS); 
	float3 normalVS = mul((float3x3)UNITY_MATRIX_IT_MV, input.normalOS);  
    float2 normalCS = normalize(mul((float2x2)UNITY_MATRIX_P, normalVS.xy));
    positionCS.xy += _OutlineWidth * normalCS;
	output.positionCS = positionCS;

    return output;
}

float4 ToonOutlinePassFragment(Varyings input) : SV_Target
{
    #ifndef _OUTLINE_ENABLE_ON
        return(float4)0;
    #endif

    UNITY_SETUP_INSTANCE_ID(input);
    UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);

    return float4(_OutlineColor, 1.0);
}


#endif